package com.efeichong.generate;

import com.efeichong.common.domain.ResponseData;
import com.efeichong.generator.DataSource;
import com.efeichong.generator.GenConfiguration;
import com.efeichong.generator.GenConstant;
import com.efeichong.generator.Generator;
import com.google.common.collect.Sets;

import java.util.Set;

/**
 * @author lxk
 * @date 2020/12/3
 * @description 代码生成
 */
public class Generate {
    public static void main(String[] args) {
        generator();
    }

    static void generator() {
        Set<String> tables = Sets.newLinkedHashSet();
        tables.add("school");
        DataSource dataSource = new DataSource();
        dataSource.setDriver("com.mysql.cj.jdbc.Driver");
        dataSource.setUrl("jdbc:mysql://localhost:3306/efeichong?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8");
        dataSource.setUsername("root");
        dataSource.setPassword("123456");
        //自定义配置
        GenConfiguration configuration = new GenConfiguration();
//        configuration.setBaseEntity(BaseEntity.class);
        configuration.setDomainPackage("com.efeichong.project.domain.entity.db");
        configuration.setDaoPackage("com.efeichong.project.domain.repository.db");
        configuration.setServicePackage("com.efeichong.project.service");
        configuration.setServiceImplPackage("com.efeichong.project.service.impl");
        configuration.setControllerPackage("com.efeichong.project.controller");
        configuration.setVoPackage("com.efeichong.project.domain.vo");
        configuration.setVuePackage("com.efeichong.project.vue");
        configuration.setResponseClazz(ResponseData.class);
//        Map map = ImmutableMap.of("meeting_company_user_ship", "sys_user"
//                , "meeting_questionnaire_user_ship", "sys_user");
        Generator generator = Generator.builder().addGenConfiguration(configuration)
                .addRequireTableNames(tables)
                .addHasExcel(true)
                .addDataSource(dataSource)
                .addHasSwagger(true)
                .addHasLombok(true)
//                .addIgnoreTableNames()
//                .addManyToManyMappedTableMap(map)
                .addGenerateModel(GenConstant.ALL)
                .build();
        generator.generate();
    }

}
